package com.miyu.system.controller.system;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.miyu.system.pojo.system.SysNotice;
import com.miyu.system.pojo.system.SysParamConfig;
import com.miyu.system.pojo.system.SysRule;
import com.miyu.system.service.system.SystemService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统控制器
 * @author miyu
 * @date 2024/02/25
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/system")
public class SystemController {
    private  final SystemService sv;
    @RequestMapping("systemHardwareInformation")
    public JSONObject SystemHardwareInformation(){

        return sv.systemHardwareInformation();
    }


    /**
     * 查询系统confirm
     *
     * @param params
     * @return {@link JSONArray }
     */
    @RequestMapping("querySysConfirm")
    public Page<SysParamConfig> querySysConfirm(@RequestBody JSONObject params){
        System.out.println("querySysConfirm");
        return sv.querySysConfirm(params);
    }

    /**
     * 系统参数编辑
     *
     * @param params
     * @return {@link JSONArray }
     */
    @RequestMapping("editSysConfirm")
    public JSONObject editSysConfirm(@RequestBody JSONObject params){
        SysParamConfig sysParamConfig = JSONObject.parseObject(params.toString(), SysParamConfig.class);
        return sv.editSysConfirm(sysParamConfig);
    }

    /**
     * 根据编码获取系统参数
     *
     * @param params
     * @return {@link SysParamConfig }
     */
    @RequestMapping("querySysConfigByCode")
    public SysParamConfig figByCode(@RequestBody JSONObject params){
        String itemCode = params.getString("itemCode");
        return sv.querySysConfigByCode(itemCode);
    }

    /**
     * 系统参数删除
     *
     * @param params
     * @return {@link JSONObject }
     */
    @RequestMapping("delSysConfirm")
    public JSONObject delSysConfirm(@RequestBody JSONArray params){
        List<SysParamConfig> sysParamConfig = JSONArray.parseArray(params.toString(), SysParamConfig.class);
        return sv.delSysConfirm(sysParamConfig);
    }

    /**
     * 保存通知
     *
     * @param notice 通知
     * @return {@link JSONObject }
     */
    @RequestMapping("saveNotice")
    public SysNotice saveNotice(@RequestBody SysNotice notice){
        return sv.saveNotice(notice);
    }

    /**
     * 查询通知
     *
     * @param notice 通知
     * @return {@link JSONObject }
     */
    @RequestMapping("queryNotice")
    public Page<SysNotice> queryNotice(@RequestBody JSONObject notice){
        return sv.queryNotice(notice);
    }

    /**
     * 保存通知
     *
     * @param notice 通知
     * @return {@link JSONObject }
     */
    @RequestMapping("deleteNotice")
    public JSONObject deleteNotice(@RequestBody List<SysNotice> notice){
        return sv.deleteNotice(notice);
    }
}
